package com.projet.whattowatch.activity;

import java.util.Locale;

import com.projet.whattowatch.R;
import com.projet.whattowatch.objet.Film;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

public class MovieDetailActivity extends FragmentActivity
{
	String titleString;
	public static Film film;
	final String EXTRA_MOVIE_NAME = "movie_name";
	
	SectionsPagerAdapter mSectionsPagerAdapter;
    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.movie_layout);
		
		Intent intent = getIntent();
		
		if(intent != null)
		{
			titleString = intent.getStringExtra(EXTRA_MOVIE_NAME);
		}
		
		for(int i = 0 ; i < MainActivity.mLibFilm.getListFilm().size(); i++)
		{
			if(MainActivity.mLibFilm.getListFilm().get(i).getNom().equals(titleString))
			{
				film = MainActivity.mLibFilm.getFilm(i);
			}
		}

        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager.setCurrentItem(0);
    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter
    {
        public SectionsPagerAdapter(FragmentManager fm)
        {
                super(fm);
        }

        @Override
        public Fragment getItem(int index)
        {
            switch (index)
            {
            case 0:
                return new MovieFragment();
            case 1:
                return new MovieFragmentResume();
            case 2:
                return new MovieFragmentCasting();
            }
            return null;
        }

        @Override
        public int getCount()
        {
                return 3;
        }

        // Defini les titre des pages
        @Override
        public CharSequence getPageTitle(int position)
        {
            Locale l = Locale.getDefault();
            switch (position)
            {
            case 0:
                    return getString(R.string.title_section_fragment).toUpperCase(l);
            case 1:
                    return getString(R.string.title_section_resume).toUpperCase(l);
            case 2:
                    return getString(R.string.title_section_casting).toUpperCase(l);
            }
            return null;
         }
    }
}